using System.IO;
namespace SB2.Core
{
    /// <summary>
    /// 用户
    /// </summary>
    public class UserAppService : ICoreService
    {
        private readonly UserRepository userRepository;
        public UserAppService(UserRepository userRepository)
        {
            this.userRepository = userRepository;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public async Task<bool> Add(UserCreateDto dto)
        {
            return await userRepository.InsertAsync(dto);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> UpdateUser(UserUpdateDto dto)
        {
            return await userRepository.UpdateAsync(dto);
        }
        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagedResponse> GetPageList(PagedRequest dto)
        {
            return await userRepository.GetPageListAsync(dto);
        }
        /// <summary>
        /// 个人登录信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<object> LoginInfo()
        {
            return (await userRepository.GetByIdAsync(UserId)).Adapt<UserDto>();
        }
    }
}